package samples.objectivefunctions;

import engine.ObjectiveFunction;
import engine.individuals.NaturalVectorIndividual;

public class PatternFunction implements
		ObjectiveFunction<NaturalVectorIndividual> {

	private final long[] pattern;
	
	public PatternFunction(long[] pattern) {
		this.pattern = pattern;
	}
	
	/** {@inheritDoc} */
	@Override
	public double compute(NaturalVectorIndividual o) {
		int result = 0;

		for (int i = 0; i < o.getSize(); i++) {
			result += Math.abs(o.getValue(i)- pattern[i]);
		}

		return -result;
	}

}
